# @Time    : 2022/7/15 21:26
# @Author  : mobai
# @Email   : 3111283671@qq.com
# @File    : hetong_page.py
# @Software: PyCharm

import unittest
from selenium import webdriver
from selenium.webdriver.common.by import By
from pages.base_pageage import BasePage
from selenium.webdriver.support.select import Select


class HeTongPage(BasePage):
    """合同初始页面"""
    url = "http://192.168.1.151/crm/index.php?m=contract"
    TJHT = (By.CSS_SELECTOR, "body > div.container > div.row > div:nth-child(1) > div > a")
    BJ = (By.CSS_SELECTOR, "#form1 > table > tbody > tr > td:nth-child(10) > a:nth-child(2)")
    XZHT = (By.CSS_SELECTOR, "#form1 > table > tbody > tr > td:nth-child(1) > input")
    RYZD = (By.ID, "field")
    XZFZR = (By.ID, "search")
    DJSS = (By.CSS_SELECTOR, "#searchForm > ul > li:nth-child(4) > button")
    DJSC = (By.ID, "delete")

    def tjht(self):
        """添加合同"""
        self.driver.find_element(*self.TJHT).click()

    def bjht(self):
        """编辑合同"""
        self.driver.find_element(*self.BJ).click()

    def rszd(self,fzr):
        """选择任意字段（负责人）"""
        select = Select(self.driver.find_element(*self.RYZD))
        select.select_by_visible_text(fzr)

    def xzfzr(self,xzfzr):
        """选择负责人（admin [办公室-CEO]）"""
        select = Select(self.driver.find_element(*self.XZFZR))
        select.select_by_visible_text(xzfzr)

    def djss(self):
        """点击搜索"""
        self.driver.find_element(*self.DJSS).click()

    def djsc(self):
        """点击删除"""
        self.driver.find_element(*self.DJSC).click()

    def xzht(self):
        """选择合同"""
        self.driver.find_element(*self.XZHT).click()
    def tkqd(self):
        """点击弹框确定"""
        self.driver.switch_to.alert.accept()
